<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
<html:xhtml />
<script type="text/javascript">
    var snpTable;
    function toggleRadio(checkbox)
    {
        if ($(checkbox).is(":checked"))
        {
            $(checkbox).parent().next().children(":radio").removeAttr("disabled");
        }
        else
        {
            $(checkbox).parent().next().children(":radio").attr("disabled", "disabled");
        }
    }

    function submit()
    {
        var sData = $('input', snpTable.fnGetNodes()).serialize();
    }

    $(document).ready(function() {
        // Clean up all checked/selected checkbox/radio buttons
        // GOTCHA: This need to be before the dataTable call
        // so that all checkbox/radio buttons are affected
        $(":checkbox:checked").removeAttr("checked");
        $(":radio:checked").removeAttr("checked");

        // Disable all radio buttons
        $(":radio").attr("disabled", "disabled");

        // 'DataTablize' the table
        snpTable = $("#snpSelectTable").dataTable({
            "bPaginate": true,
            "sPaginationType": "full_numbers",
            "bFilter": true,
            "bJQueryUI": true,
            "bAutoWidth": false,
            "aoColumns": [{"sType": "html"},
                {"sType": "html"},
                {"bSortable": false, "bSearchable": false},
                {"bSortable": false, "bSearchable": false}],
            "aaSorting": [[1,"asc"]]
        });
    });
</script>
<div id="geneGeneParameters" class="content input list">
    <h2>
        Gene Gene Interaction Parameters
    </h2>
    <html:form action="geneGeneSubmit">
        <html:errors property="snpSelection" />
        <html:errors property="snpSelectionGene" />
        <html:errors property="conditioningSnps" />
        <table id="snpSelectTable" cellpadding="0" cellspacing="0" border="0" class="display">
            <thead>
                <tr>
                    <th>RS number</th>
                    <th>Gene</th>
                    <th>Select</th>
                    <th>Conditioning Marker</th>
                </tr>
            </thead>
            <tbody>
                <logic:iterate id="snp" name="geneGeneInteractionForm" property="snps">
                    <tr>
                        <td>
                            <a href="<html:rewrite page='/snpSummary.do' />?rsNumber=<bean:write name='snp' property='rsNumber'/>">
                                <bean:write name='snp' property='rsNumber'/>
                            </a>
                        </td>
                        <td>
                            <a href="<html:rewrite page='/geneSummary.do' />?geneName=<bean:write name='snp' property='gene.name'/>">
                                <bean:write name="snp" property="gene.name"/>
                            </a>
                        </td>
                        <td class="inputbox">
                            <input type="checkbox" name="selectedSnps" value="<bean:write name='snp' property='rsNumber'/>" onclick="toggleRadio(this);" />
                        </td>
                        <td class="inputbox">
                            <input type="radio" name="conditioningSnps" value="<bean:write name='snp' property='rsNumber'/>" />
                        </td>
                    </tr>
                </logic:iterate>
            </tbody>
        </table>
        <dl>
            <dt>Phenotype</dt>
            <dd>
                <html:select name="geneGeneInteractionForm" property="selectedPhenotype">
                    <html:optionsCollection property="phenotypes" label="name" value="name" />
                </html:select>
            </dd>
            <dd class="button"><html:submit value="Analyze" property="submitType" /></dd>
        </dl>
    </html:form>
</div>